package com.qf.feign;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

@FeignClient(value = "SMSPLATFORM-CACHE", fallback = CacheServiceFallback.class)
public interface CacheService {
    @RequestMapping(value = "/cache/get/{key}", method = RequestMethod.GET)
    String get(@PathVariable("key") String key);

    @RequestMapping(value = "/cache/getobject/{key}", method = RequestMethod.GET)
    Object getObject(@PathVariable("key") String key);

    @RequestMapping(value = "/cache/delete", method = RequestMethod.POST)
    boolean del(@RequestParam("keys") String... keys);

    @RequestMapping(value = "/cache/hmset/{key}", method = RequestMethod.POST)
    void hmset(@PathVariable("key") String key, @RequestBody Map map);

    @RequestMapping(value = "/cache/hmget/{key}", method = RequestMethod.GET)
    public Map hmget(@PathVariable("key") String key);

    @RequestMapping(value = "/cache/save2cachewithexpire", method = RequestMethod.POST)
    void set(@RequestParam("key") String key, @RequestParam("value") String value, @RequestParam("expireSecond") Long expireSecond);

    @RequestMapping(value = "/cache/save2cache/{key}/{value}", method = RequestMethod.POST)
    void saveCache(@PathVariable("key") String key, @PathVariable("value") String value);

    @RequestMapping(value = "/cache/incr", method = RequestMethod.GET)
    public Long incr(@RequestParam("key") String key, @RequestParam("delta") long value);

    @PostMapping("/cache/pipel")
    List<Object> pipelineOps(@RequestBody Map<String, Object> map);


    @PostMapping("/cache/add2set")
    public  Long add2Set(@RequestParam("key") String key,@RequestParam("members") List<String> members) ;

    /**
     * 从set中获取所有数据
     */
    @GetMapping("/cache/members/{key}")
    public Set<String> members(@PathVariable String key) ;

    /**
     * 判断某个数据在不在redis的set中
     *
     */
    @GetMapping("/cache/ismember/{key}/{member}")
    public Boolean isMember(@PathVariable String key, @PathVariable String member) ;

    @PostMapping("/cache/zadd")
    public Boolean add2Zent(@RequestParam String key,@RequestParam String value,@RequestParam double score);

    @GetMapping("/cache/zrange")
    public Long getSizeByScore(@RequestParam String key,@RequestParam  double min,@RequestParam   double max);

    @GetMapping("/cache/rangewithscores")
    Set<Map> getDataFromZsetByIndex(@RequestParam String key,@RequestParam int start,@RequestParam int end);


    @PostMapping("/cache/rpush")
    Long rPush(@RequestParam String key,@RequestParam String...values);

    //    从 List 中获取指定位置的数据
    @GetMapping("/cache/lrange")
    List<String> getDataFromList(@RequestParam String key,@RequestParam int start,@RequestParam int end);

    //  从list 中一次性删除多个数据
    @PostMapping("/cache/lremove")
    Long lremove(@RequestParam String key,@RequestParam String... values);


    @GetMapping("/cache/hincr")
    public Long hIncr(@RequestParam String key, @RequestParam String field,@RequestParam Long delta);
    //  获取指定key  指定field 得值
    @GetMapping("/cache/HGet/{key}/{field}")
    public String HGet(@PathVariable String key,@PathVariable String field);


}
